<?php

/**
 * Erra_Fields_Text - Callback field
 *
 * @package
 * @author Alexis Eric
 * @copyright Copyright (c) 2012 - Erra Prod
 * @version $1.0$
 * @access public
 */
class Erra_Fields_Callback extends Erra_Fields_Base_Field {
    protected $_callback = 'CallbackAction/customCallback';
    protected $_parent = null;
    protected $_actionName = 'Execute';

    function __construct($objectId) {
        parent::__construct($objectId);
        $this->setDatabaseType('none');
    }

    /**
     * Shows callback button
     *
     * @param mixed $lang
     * @return
     */
    public function editInstance(Array $extraProperties=null) {
        $res = '';
        $extraProperties = is_null($extraProperties) ? array('class'=>'erra-form-common-submit_button') : $extraProperties;
        $res = '<div class="erra-form-field-callback>';
        if ($this->_parent != null) {
            $res .= Erra_System_FormRenderer::startCallbackForm($this->_parent, $this->_callback, true);
            $res .= '<span class="erra___field_description">' . $this->getDescription() . '</span>';
            $res .= '<input type="hidden" name="CheckList:' . $this->_parent->getObjectClass() . '" value="" />';
            if ($this->_actionName != null) {
                $res .= '<center><input '.$this->getHtmlAttributes($extraProperties).' onclick="get_selected_id(\'' . $this->_parent->getObjectId() . '\')" name="' . $this->function . '" type="submit" value="' . $this->_actionName . '"/></center>';
            }
            $res .= Erra_System_FormRenderer::endForm($this->_parent);
        }
        $res .= '</div>';
        return $res;
    }

    function toHtml($displayParameters=null) {
        return $this->getRawData();
    }

    public function getCallback() {
        return $this->_callback;
    }

    public function setCallback($callback) {
        $this->_callback = $callback;
        return $this;
    }
    public function getParent() {
        return $this->_parent;
    }

    public function setParent($parent) {
        $this->_parent = $parent;
        return $this;
    }
    
    public function setActionName($actionName) {
        $this->_actionName = $actionName;
        return $this;
    }
}